//
//  XZTrainStationCell.m
//  生活小助手
//
//  Created by lixiangzhou on 14-8-7.
//  Copyright (c) 2014年 lxz. All rights reserved.
//

#import "XZTrainStationCell.h"
#import "XZTrainNumStation.h"



@interface XZTrainStationCell ()
@property (weak, nonatomic) UILabel *stationNameLabel;
@property (weak, nonatomic) UILabel *arrivedTimeLabel;
@property (weak, nonatomic) UILabel *leaveTimeLabel;
@property (weak, nonatomic) UILabel *stayLabel;
@property (weak, nonatomic) UILabel *mileageLabel;
@end

@implementation XZTrainStationCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"cell";
    XZTrainStationCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[XZTrainStationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        /* ------------------站点名称------------------*/
        UILabel *stationNameLabel = [[UILabel alloc] init];
        stationNameLabel.font = kFont;
        stationNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:stationNameLabel];
        self.stationNameLabel = stationNameLabel;
        
        /* ------------------到达时间------------------*/
        UILabel *arrivedTimeLabel = [[UILabel alloc] init];
        arrivedTimeLabel.font = kFont;
        arrivedTimeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:arrivedTimeLabel];
        self.arrivedTimeLabel = arrivedTimeLabel;
        
        /* ------------------发车时间------------------*/
        UILabel *leaveTimeLabel = [[UILabel alloc] init];
        leaveTimeLabel.font = kFont;
        leaveTimeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:leaveTimeLabel];
        self.leaveTimeLabel = leaveTimeLabel;
        
        /* ------------------停留------------------*/
        UILabel *stayLabel = [[UILabel alloc] init];
        stayLabel.font = kFont;
        stayLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:stayLabel];
        self.stayLabel = stayLabel;
        
        /* ------------------里程------------------*/
        UILabel *mileageLabel = [[UILabel alloc] init];
        mileageLabel.font = kFont;
        mileageLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:mileageLabel];
        self.mileageLabel = mileageLabel;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    CGFloat width = self.contentView.width / 5;
    
    self.stationNameLabel.x = 0;
    self.arrivedTimeLabel.x = kStationNameWidth;
    self.leaveTimeLabel.x = self.arrivedTimeLabel.x + kArrivedTimeWidth;
    self.stayLabel.x = self.leaveTimeLabel.x + kLeaveTimeWidth;
    self.mileageLabel.x = self.stayLabel.x + kStayWidth;
    
    self.stationNameLabel.width = kStationNameWidth;
    self.arrivedTimeLabel.width = kArrivedTimeWidth;
    self.leaveTimeLabel.width = kLeaveTimeWidth;
    self.stayLabel.width = kStayWidth;
    self.mileageLabel.width = kMileageWidth;
    
    self.stationNameLabel.height = self.height;
    self.arrivedTimeLabel.height = self.height;
    self.leaveTimeLabel.height = self.height;
    self.stayLabel.height = self.height;
    self.mileageLabel.height = self.height;
}

- (void)setTrainStation:(XZTrainNumStation *)trainStation
{
    _trainStation = trainStation;
    
    self.stationNameLabel.text = trainStation.station_name;
    self.arrivedTimeLabel.text = trainStation.arrived_time;
    self.leaveTimeLabel.text = trainStation.leave_time;
    self.stayLabel.text = trainStation.stay;
    self.mileageLabel.text = trainStation.mileage;
}

@end
